#!/bin/bash
#set -x
preurl=azurepre.southeastasia.cloudapp.azure.com
produrl=app.tls4.io
qcurl=dev2-tls.y3technologies.com

if [[ $1 == "lova-pre" ]];then
for service in `cat /root/script/checkver.txt|grep -v ^#`
do
    testver=`curl -s https://$qcurl/lova-test/$service/api/v1/service/version|awk -F : '{print $4}'|awk -F '"' '{print $2}'`
    qcver=`curl -s https://$qcurl/qc/$service/api/v1/service/version|awk -F : '{print $4}'|awk -F '"' '{print $2}'`
    prever=`curl -s http://$preurl/$service/api/v1/service/version|awk -F : '{print $4}'|awk -F '"' '{print $2}'`
    testmobver=`curl -s https://$qcurl/lova-test/sto/api/v1/service/version/mobile|awk -F : '{print $NF}'|awk -F '"' '{print $2}'`
    qcmobver=`curl -s https://$qcurl/qc/sto/api/v1/service/version/mobile|awk -F : '{print $NF}'|awk -F '"' '{print $2}'`
    premobver=`curl -s http://$preurl/sto/api/v1/service/version/mobile|awk -F : '{print $NF}'|awk -F '"' '{print $2}'`
    testappver=`curl -s https://$qcurl/lova-test/app/lova/resource/static/version.json|grep "data"|awk -F : '{print $2}'|awk -F '"' '{print $2}'`
    qcappver=`curl -s https://$qcurl/qc/app/lova/resource/static/version.json|grep "data"|awk -F : '{print $2}'|awk -F '"' '{print $2}'`
    preappver=`curl -s http://$preurl/app/lova/resource/static/version.json|grep "data"|awk -F : '{print $2}'|awk -F '"' '{print $2}'`
if [[ $2 == "hotfix" ]];then
  if [[ $service == "lova-mobile" ]];then
    if [[ $qcmobver == $premobver ]];then
      sleep 0.1
    else
      echo "qc&pre $qcmobver - lova-mobile not equal $premobver - lova-mobile"
    fi
  elif [[ $service == "lova-app" ]];then
    if [[ $qcappver == $preappver ]];then
      sleep 0.1
    else
      echo "qc&pre $qcappver - lova-app not equal $preappver - lova-app"
    fi
  else
    if [[ $qcver == $prever ]];then
      sleep 0.1
    else
      echo "qc&pre $qcver not equal $prever"
    fi
  fi
else
  if [[ $service == "lova-mobile" ]];then
    if [[ $testmobver == $premobver ]];then
      sleep 0.1
    else
      echo "lova-test&pre $testmobver - lova-mobile not equal $premobver - lova-mobile"
    fi
  elif [[ $service == "lova-app" ]];then
    if [[ $testappver == $preappver ]];then
      sleep 0.1
    else
      echo "lova-test&pre $testappver - lova-app not equal $preappver - lova-app"
    fi
  else
    if [[ $testver == $prever ]];then
      sleep 0.1
    else
      echo "lova-test&pre $testver not equal $prever"
    fi
  fi
fi
done
elif [[ $1 == "lova-prod" ]];then
for service in `cat /root/script/checkver.txt|grep -v ^#`
do
    prever=`curl -s http://$preurl/$service/api/v1/service/version|awk -F : '{print $4}'|awk -F '"' '{print $2}'`
    prodver=`curl -s https://$produrl/$service/api/v1/service/version|awk -F : '{print $4}'|awk -F '"' '{print $2}'`
    premobver=`curl -s http://$preurl/sto/api/v1/service/version/mobile|awk -F : '{print $NF}'|awk -F '"' '{print $2}'`
    prodmobver=`curl -s https://$produrl/sto/api/v1/service/version/mobile|awk -F : '{print $NF}'|awk -F '"' '{print $2}'`
    preappver=`curl -s http://$preurl/app/lova/resource/static/version.json|grep "data"|awk -F : '{print $2}'|awk -F '"' '{print $2}'`
    prodappver=`curl -s https://$produrl/app/lova/resource/static/version.json|grep "data"|awk -F : '{print $2}'|awk -F '"' '{print $2}'`

if [[ $service == "lova-mobile" ]];then
  if [[ $premobver == $prodmobver ]];then
    sleep 0.1
  else
    echo "pre&prod $premobver - lova-mobile not equal $prodmobver - lova-mobile"
  fi
elif [[ $service == "lova-app" ]];then
  if [[ $preappver == $prodappver ]];then
    sleep 0.1
  else
    echo "pre&prod $preappver - lova-app not equal $prodappver - lova-app"
  fi
else
  if [[ $prever == $prodver ]];then
    sleep 0.1
  else
    echo "pre&prod $prever not equal $prodver"
  fi
fi
done
elif [[ $1 == "lova-trial" ]];then
for service in `cat /root/script/checkver.txt|grep -v ^#`
do
    prever=`curl -s http://$preurl/$service/api/v1/service/version|awk -F : '{print $4}'|awk -F '"' '{print $2}'`
    trialver=`curl -s https://$qcurl/lova-trial/$service/api/v1/service/version|awk -F : '{print $4}'|awk -F '"' '{print $2}'`
    premobver=`curl -s http://$preurl/sto/api/v1/service/version/mobile|awk -F : '{print $NF}'|awk -F '"' '{print $2}'`
    trialmobver=`curl -s https://$qcurl/qc/sto/api/v1/service/version/mobile|awk -F : '{print $NF}'|awk -F '"' '{print $2}'`
    preappver=`curl -s http://$preurl/app/lova/resource/static/version.json|grep "data"|awk -F : '{print $2}'|awk -F '"' '{print $2}'`
    trialappver=`curl -s https://$qcurl/lova-trial/app/lova/resource/static/version.json|grep "data"|awk -F : '{print $2}'|awk -F '"' '{print $2}'`

if [[ $service == "lova-mobile" ]];then
  if [[ $premobver == $trialmobver ]];then
    sleep 0.1
  else
    echo "pre&trial $premobver - lova-mobile not equal $trialmobver - lova-mobile"
  fi
elif [[ $service == "lova-app" ]];then
  if [[ $preappver == $trialappver ]];then
    sleep 0.1
  else
    echo "pre&trial $preappver - lova-app not equal $trialappver - lova-app"
  fi
else
  if [[ $prever == $trialver ]];then
    sleep 0.1
  else
    echo "pre&trial $prever not equal $trialver"
  fi
fi
done
else
  echo "Please enter the correct parameters:qc,lova-pre,lova-prod,lova-trial"
  exit 1
fi


